# encoding: utf-8
# id           | integer                     | not null default nextval('parcelas_id_seq'::regclass)
# data         | date                        | 
# valor        | numeric(10,2)               | 
# ordem        | integer                     | 
# transacao_id | integer                     | 
# parcelado_id | integer                     | 
# created_at   | timestamp without time zone | not null
# updated_at   | timestamp without time zone | not null
class Parcela < ActiveRecord::Base
  attr_protected

  belongs_to :debito, :foreign_key => "transacao_id",
  	:dependent => :destroy

  belongs_to :parcelado
  
  validates :data, :valor, :ordem, :parcelado,
  	:presence => true
  	
  validates :ordem,
  	:numericality => { :greater_than_or_equal_to => 1,
  											:only_integer => true }

  validates :valor,
  	:numericality => { :greater_than => 0 }

	#
	#
	def observacao
		"#{parcelado.observacao} (#{ordem}/#{parcelado.parcelas})"
	end

	#
	#
	def quitada?
		!debito.nil? and !debito.conta.nil? and debito.quitada?
	end

end
